package cn.com.bluemoon.daps.model.core.file.mysql;

import cn.com.bluemoon.daps.common.domain.ResultBean;
import cn.com.bluemoon.daps.common.validation.illegal.IllegalChar;
import cn.com.bluemoon.daps.model.core.file.TableData;
import cn.com.bluemoon.daps.model.entity.DapDataModelTable;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentRowHeight;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 * <pre>
 *
 * </p>   序号	表英文名	表中文名	表业务描述	标签	组路径	主题	表分类	stored as	SERDEPROPERTIES	TBLPROPERITIES
 * </p>1	b2b_User_Huanxin_Info	用户环信信息表			ODS/XXX组	一级主题/二级主题/三级主题	维表	PARQUET
 *
 * </pre>
 *
 * @author Jarod.Kong
 * @date 2021/2/5 12:01
 */
@ColumnWidth(20)
@HeadRowHeight(15)
@ContentRowHeight(20)
public class MySqlTableData extends TableData {

    // common props
    @ExcelProperty(value = "序号")
    @ColumnWidth(8)
    private Integer order;

    //    @NoSqlKeyword(dbtype = DbType.mysql, name = "表英文名")
    @IllegalChar(message = "表英文名存在非法字符")
    @ExcelProperty("表英文名")
    @NotNull(message = "表英文名不可为空")
    @Size(max = 64, message = "表英文名不可以大于{max}")
    private String tableName;

    @ExcelProperty("表中文名")
    @NotNull(message = "表中文名不可为空")
    @Size(max = 2048, message = "表中文名不可以大于{max}")
    private String tableNameZh;

    @Size(max = 1024, message = "业务描述不可以大于{max}")
    @ExcelProperty("表业务描述")
    private String bizDesc;

    // @MyTableGroup
    @ExcelProperty(value = "组路径")
    @NotNull(message = "组路径不可为空")
    private String groupPathName;

    @Override
    public String getTopicName() {
        return null;
    }

    /**
     * 用于数据库表模型转为导出模型
     *
     * @param table 据库表模型
     */
    @Override
    public MySqlTableData copyDbProperties0(DapDataModelTable table) {
        super.copyDbProperties0(table);
        setTableName(table.getEngName());
        setTableNameZh(table.getName());
        setBizDesc(table.getBusinessDesc());
        return this;
    }


    /**
     * @param modelTable 转为
     * @return
     */
    @Override
    protected ResultBean<DapDataModelTable> convertToModel0(DapDataModelTable modelTable) {

        return ResultBean.ok(modelTable);
    }

    public static MySqlTableData getInstance(){
        return new MySqlTableData();
    }

    @Override
    public Integer getOrder() {
        return order;
    }

    public void setOrder(Integer order) {
        this.order = order;
    }

    @Override
    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    @Override
    public String getTableNameZh() {
        return tableNameZh;
    }

    public void setTableNameZh(String tableNameZh) {
        this.tableNameZh = tableNameZh;
    }

    @Override
    public String getBizDesc() {
        return bizDesc;
    }

    public void setBizDesc(String bizDesc) {
        this.bizDesc = bizDesc;
    }

    @Override
    public String getGroupPathName() {
        return groupPathName;
    }

    @Override
    public void setGroupPathName(String groupPathName) {
        this.groupPathName = groupPathName;
    }

    @Override
    public void setTopicName(String topicName) {
        // nothing
    }
}
